package Gui;
import com.cloudgarden.resource.SWTResourceManager;

import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/


/**
* Description :Add To Listener a Direct
* <p>
*
*@author Danielle 
*/
public class AddToListener extends org.eclipse.swt.widgets.Composite {

	{
		//Register as a resource user - SWTResourceManager will
		//handle the obtaining and disposing of resources
		SWTResourceManager.registerResourceUser(this);
	}
	
	private Composite allView;
	private Label select;
	private Text textSelect;
	private Button cancel;
	private Button add;
	private Button brows;
	static Shell shell;
	private Button bowseFile;
	static String returnString;
	/**
	* Auto-generated main method to display this 
	* org.eclipse.swt.widgets.Composite inside a new Shell.
	*/
	
	/**
	* Overriding checkSubclass allows this class to extend org.eclipse.swt.widgets.Composite
	*/	
	protected void checkSubclass() {
	}
	
	/**
	* Auto-generated method to display this 
	* org.eclipse.swt.widgets.Composite inside a new Shell.
	*/
	public static String showGUI() {
		Display display = Display.getDefault();
		shell = new Shell(display);
		AddToListener inst = new AddToListener(shell, SWT.NULL);
		Point size = inst.getSize();
		shell.setLayout(new FillLayout());
		shell.layout();
		if(size.x == 0 && size.y == 0) {
			inst.pack();
			shell.pack();
		} else {
			Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
			shell.setSize(shellBounds.width, shellBounds.height);
		}
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		return returnString;
	}

	public AddToListener(org.eclipse.swt.widgets.Composite parent, int style) {
		super(parent, style);
		initGUI();
	}

	private void initGUI() {
		try {
			FormLayout thisLayout = new FormLayout();
			this.setLayout(thisLayout);
			{
				allView = new Composite(this, SWT.NONE);
				FormLayout allViewLayout = new FormLayout();
				FormData allViewLData = new FormData();
				allViewLData.left =  new FormAttachment(0, 1000, 0);
				allViewLData.top =  new FormAttachment(0, 1000, 0);
				allViewLData.width = 400;
				allViewLData.height = 159;
				allView.setLayoutData(allViewLData);
				allView.setLayout(allViewLayout);

				{
					cancel = new Button(allView, SWT.PUSH | SWT.CENTER);
					FormData cancelLData = new FormData();
					cancelLData.left =  new FormAttachment(0, 1000, 233);
					cancelLData.top =  new FormAttachment(0, 1000, 101);
					cancelLData.width = 65;
					cancelLData.height = 25;
					cancel.setLayoutData(cancelLData);
					cancel.setText("cancel");
					cancel.setFont(SWTResourceManager.getFont("Tahoma", 9, 0, false, false));
					cancel.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(SelectionEvent evt) {
							///sign that we had cancel
							returnString=null;
							///close:
							shell.dispose();
						}
					});
				}
				{
					add = new Button(allView, SWT.PUSH | SWT.CENTER);
					FormData addLData = new FormData();
					addLData.left =  new FormAttachment(0, 1000, 86);
					addLData.top =  new FormAttachment(0, 1000, 101);
					addLData.width = 68;
					addLData.height = 25;
					add.setLayoutData(addLData);
					add.setText("Add");
					add.setFont(SWTResourceManager.getFont("Tahoma", 9, 0, false, false));
					add.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(SelectionEvent evt) {
							///sign that we had add
							shell.dispose();
						}
					});
				}
				{
					brows = new Button(allView, SWT.PUSH | SWT.CENTER);
					FormData browsLData = new FormData();
					browsLData.left =  new FormAttachment(0, 1000, 285);
					browsLData.top =  new FormAttachment(0, 1000, 43);
					browsLData.width = 96;
					browsLData.height = 23;
					brows.setLayoutData(browsLData);
					brows.setText("Browse Folder");
					brows.setFont(SWTResourceManager.getFont("Tahoma", 9, 0, false, false));
					brows.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(SelectionEvent evt) {
							DirectoryDialog dlg = new DirectoryDialog(shell);
							dlg.setFilterPath(textSelect.getText());
							dlg.setText("SWT's DirectoryDialog");
							dlg.setMessage("Select a directory");
					        String dir = dlg.open();
					        if (dir != null) {
					        	textSelect.setText(dir);
					        	returnString=dir;
					        
					        }
						}
					});
				}
				{
					FormData textSelectLData = new FormData();
					textSelectLData.left =  new FormAttachment(0, 1000, 23);
					textSelectLData.top =  new FormAttachment(0, 1000, 43);
					textSelectLData.width = 250;
					textSelectLData.height = 20;
					textSelect = new Text(allView, SWT.NONE);
					textSelect.setLayoutData(textSelectLData);
				}
				{
					select = new Label(allView, SWT.NONE);
					FormData selectLData = new FormData();
					selectLData.width = 124;
					selectLData.height = 22;
					selectLData.left =  new FormAttachment(273, 1000, 0);
					selectLData.right =  new FormAttachment(583, 1000, 0);
					selectLData.top =  new FormAttachment(97, 1000, 0);
					selectLData.bottom =  new FormAttachment(235, 1000, 0);
					select.setLayoutData(selectLData);
					select.setText("Select folder :");
					select.setFont(SWTResourceManager.getFont("Tahoma", 11, 0, false, false));
				}
			}
			this.layout();
			pack();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
